package com.sparrow.annotation.bean;

import lombok.Data;
import lombok.experimental.Accessors;
import org.springframework.util.StringUtils;
import org.springframework.web.bind.annotation.RequestMethod;

/**
 * Created by wancheng on 2019/2/15.
 */
@Data
@Accessors(chain = true)
public class RequestUriInfo implements Comparable<RequestUriInfo> {
    /**
     * controller名称
     */
    private String controllerName;
    /**
     * controller url映射
     */
    private String controllerMapping;
    /**
     * mapping的名称
     */
    private String name;
    /**
     * mapping的请求路径
     */
    private String value;
    /**
     * 响应请求的方法
     */
    private RequestMethod requestMethod;

    public RequestUriInfo() {

    }

    public RequestUriInfo(String name) {
        super();
        this.name = name;
    }

    public String getWholeUri(){
        if (!StringUtils.isEmpty(controllerMapping)){
            return controllerMapping+value;
        }
        return value;
    }
    @Override
    public String toString() {
        return "RequestUriInfo{" +
                "controllerName='" + controllerName + '\'' +
                ", controllerMapping='" + controllerMapping + '\'' +
                ", name='" + name + '\'' +
                ", value='" + value + '\'' +
                ", requestMethod=" + requestMethod +
                '}';
    }

    /**
     * 根据请求路径对请求信息进行区分。
     */
    @Override
    public int compareTo(RequestUriInfo o) {
        return this.value.compareTo(o.getValue());
    }
}
